<template>
  <el-dialog
    title='product-page'
    size="large"
    class="login-form "
    width="470px"
    :close-on-click-modal="false"
    :destroy-on-close="true"
    :lock-scroll="false"
    :visible="visible"
    label-width="120px"
    :before-close="handleClose">
    <div class="second_block">
      <br>
      <div style="font-size: 15px;text-align: center;color: white;">{{script_1}}</div>
      <br>
      <div style="font-size: 15px;text-align: center;color: white;">{{script_2}}</div>
      <br>
      <el-form
        :model="form"
        ref="form"
        :rules="rules"
        label-width="115px">
        <el-form-item
          prop="name">
            <span slot="label">
              <span style="color: #000;font-weight: 700;">Name:</span>
            </span>
          <el-input
            :maxlength="25"
            v-model="form.order_name"
            placeholder="Enter Your Name..."
            clearable/>
        </el-form-item>
        <el-form-item
          prop="email">
            <span slot="label">
              <span style="color: #000;font-weight: 700;">Email:</span>
            </span>
          <el-input
            :maxlength="40"
            v-model="form.order_email"
            placeholder="Enter Your Email..."
            clearable/>
        </el-form-item>
        <el-form-item
          v-if="phone_require==1"
          prop="phone">
            <span slot="label">
              <span style="color: #000;font-weight: 700;">Phone:</span>
            </span>
          <el-input
            :maxlength="20"
            v-model="form.phone"
            placeholder="Enter Your Phone..."
            clearable/>
        </el-form-item>
        <el-form-item
          prop="address">
            <span slot="label">
              <span style="color: #000;font-weight: 700;">Address:</span>
            </span>
          <el-input
            :maxlength="50"
            v-model="form.address"
            placeholder="Enter Your Address..."
            clearable/>
        </el-form-item>
        <el-form-item
          prop="state">
            <span slot="label">
              <span style="color: #000;font-weight: 700;">State/Region:</span>
            </span>
          <el-input
            :maxlength="30"
            v-model="form.state"
            placeholder="Enter Your State/Region..."
            clearable/>
        </el-form-item>
        <el-form-item
          prop="postal_code">
            <span slot="label">
              <span style="color: #000;font-weight: 700;">Postal Code:</span>
            </span>
          <el-input
            :maxlength="30"
            v-model="form.postal_code"
            placeholder="Enter Your Postal Code..."
            clearable/>
        </el-form-item>
        <el-form-item
          prop="country">
            <span slot="label">
              <span style="color: #000;font-weight: 700;">Country:</span>
            </span>
          <el-input
            :maxlength="30"
            v-model="form.country"
            placeholder="Enter Your Country..."
            clearable/>
        </el-form-item>
        <el-form-item
          prop="city">
            <span slot="label">
              <span style="color: #000;font-weight: 700;">City:</span>
            </span>
          <el-input
            :maxlength="20"
            v-model="form.city"
            placeholder="Enter Your City..."
            clearable/>
        </el-form-item>

      </el-form>

      <div style="text-align: center">
        <el-button type="warning" @click="doConfirmProduct">Confirm</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "product-page",
  props: {
    // 弹窗是否打开
    visible: Boolean,
    data: Object,
  },
  data() {
    return {
      // 表单数据
      form: this.data,
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      script_1:'',
      script_2:'',
      phone_require:1,
    };
  },
  computed: {
    // 表单验证规则
    rules() {
      return {
        order_name: [
          {required: true, message: 'Enter Your Name...', type: 'string', trigger: 'blur'}
        ],
        order_email: [
          {required: true, message: 'Enter Your Email...', type: 'string', trigger: 'blur'}
        ],
        phone: [
          {required: true, message: 'Enter Your Phone...', type: 'string', trigger: 'blur'}
        ],
        address: [
          {required: true, message: 'Enter Your Address...', type: 'string', trigger: 'blur'}
        ],
        state: [
          {required: true, message: 'Enter Your State/Region...', type: 'string', trigger: 'blur'}
        ],
        postal_code: [
          {required: true, message: 'Enter Your Postal Code...', type: 'string', trigger: 'blur'}
        ],
        country: [
          {required: true, message: 'Enter Your Country...', type: 'string', trigger: 'blur'}
        ],
        city: [
          {required: true, message: 'Enter Your City...', type: 'string', trigger: 'blur'}
        ],
      };
    },
    // 当前语言
    language() {
      return this.$i18n.locale;
    }
  },
  mounted () {
  },
  methods : {
    setForm(form)
    {
      this.form = form;
      this.form.order_name = form.name;
      this.form.order_email = form.email;
    },
    setBuyerConfig(data){
      this.script_1 = data.gift_product_page_script.script_1;
      this.script_2 = data.gift_product_page_script.script_2;
      this.phone_require = data.phone_require;
    },
    //关闭页面
    handleClose(done) {
      done();
      this.$emit('handleClose');
    },
    //跳转结束流程
    doConfirmProduct()
    {
      this.$refs['form'].validate((valid) => {
        if (!valid) {
          return false;
        }else{
          this.$emit('doConfirmProduct',this.form);
        }
      });
    }
  }
}
</script>

<style scoped>

::v-deep .el-rate__icon{
  font-size: 30px;
}

</style>
